package com.vhall.component.controller.rbac.adm;

import com.vhall.component.entity.rbac.vo.*;
import com.vhall.component.framework.common.annotation.VhallComponent;
import com.vhall.component.plugin.common.annotation.TokenAuth;
import com.vhall.component.plugin.common.enums.OperateTypeEnum;
import com.vhall.component.service.annotation.OperateLog;
import com.vhall.component.service.rbac.RbacAdminMenuService;
import com.vhall.component.service.rbac.RbacMenuService;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @author xianglei
 * @date 2021/4/28 16:38
 */
@Slf4j
@VhallComponent
@Tag(name = "菜单列表-管理端")
public class RbacAdminMenuController implements RbacAdminMenuFacade {

    @Autowired
    private RbacAdminMenuService rbacAdminMenuService;
    @Autowired
    private RbacMenuService menuService;

    /**
     * 获取菜单列表
     *
     * @param reqVo
     * @return
     */
    @Override
    @TokenAuth("sys:menu:list")
    public List<AdminMenuListRspVo> menuList(AdminMenuListReqVo reqVo) {
        return rbacAdminMenuService.getList(reqVo);
    }

    @TokenAuth("sys:menu:add")
    @Override
    @OperateLog(type = OperateTypeEnum.CREATE, name = "菜单-添加")
    public MenuesVO add(MenuAddReqVO reqVO) {
        return menuService.add(reqVO);
    }

    @TokenAuth("sys:menu:del")
    @Override
    @OperateLog(type = OperateTypeEnum.DELETE, name = "菜单-删除")
    public List<Integer> delete(MenuDeleteReqVO reqVO) {
        return menuService.batchDelete(reqVO);
    }

    @TokenAuth("sys:menu:edit")
    @Override
    @OperateLog(type = OperateTypeEnum.UPDATE, name = "菜单-编辑")
    public Boolean edit(MenuEditReqVO reqVO) {
        return menuService.edit(reqVO);
    }

    @TokenAuth("sys:menu:edit")
    @Override
    @OperateLog(type = OperateTypeEnum.UPDATE, name = "菜单-排序")
    public Boolean setSort(SetSortReqVO reqVO) {
        MenuEditReqVO vo = new MenuEditReqVO();
        vo.setMenuId(reqVO.getMenuId());
        vo.setSort(reqVO.getSort());
        return menuService.updateSortOrStatus(vo);
    }

    @TokenAuth("sys:menu:edit")
    @Override
    @OperateLog(type = OperateTypeEnum.UPDATE, name = "菜单-更新状态")
    public Boolean changeStatus(ChangeStatusReqVO reqVO) {
        MenuEditReqVO vo = new MenuEditReqVO();
        vo.setMenuId(reqVO.getMenuId());
        vo.setStatus(reqVO.getStatus());
        return menuService.updateSortOrStatus(vo);
    }

    @Override
    @OperateLog(type = OperateTypeEnum.CREATE, name = "菜单-添加子菜单")
    public MenuesVO addChildMenu(MenuAddReqVO reqVO) {
        return menuService.add(reqVO);
    }
}
